package com.qo.qsdk.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

import com.qo.qsdk.ui.base.LoadingProgressView;
import com.qo.qsdk.utils.DynamicUtils;
import com.qo.qsdk.utils.Language;

public class LoadingDialog extends Dialog {

    private LoadingProgressView mLoadingProgressView;

    public interface LoadingDialogListener {
        void onBackPressed();
    }

    private LoadingDialogListener mLoadingDialogListener;
    public LoadingDialog(Activity activity, LoadingDialogListener loadingDialogListener) {
        super(activity, DynamicUtils.style(activity, "qsdk_loading_progress_style"));
        this.mLoadingDialogListener = loadingDialogListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLoadingProgressView = new LoadingProgressView(getContext());
        setContentView(mLoadingProgressView.getMain());
        setCanceledOnTouchOutside(false);
        setCancelable(false);
//        setOnDismissListener(new OnDismissListener() {
//            @Override
//            public void onDismiss(DialogInterface dialog) {
//                mLoadingProgressView.stop();
//                if (mLoadingDialogListener != null) mLoadingDialogListener.onBackPressed();
//            }
//        });
    }

    @Override
    public void show() {
        super.show();
        mLoadingProgressView.show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (mLoadingProgressView != null) mLoadingProgressView.stop();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
//        mLoadingProgressView.stop();
//        if (mLoadingDialogListener != null) mLoadingDialogListener.onBackPressed();
//        dismiss();
    }
}
